package com.ittest.mapper.system;


import com.ittest.domain.system.Role;
import com.ittest.domain.system.SysLog;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 角色管理Mpper层接口
 */
public interface RoleMapper {
    // 查询所有
    @Select("select * from role")
    List<Role> findAll();
    @Select("select id,roleName,roleDesc," +
            " case" +
            " when id in (select roleId from users_role where userId =#{id}) " +
            " then '1' " +
            " else '0' " +
            " end " +
            " as flag " +
            " from  role")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "roleName",property = "roleName"),
            @Result(column = "roleDesc",property = "roleDesc"),
            @Result(column = "flag",property = "flag")
    })
    List<Role> findRoleByUserId(String id);

    // 新增操作
    @Insert("insert into role values(#{id},#{roleName},#{roleDesc})")
    void save(Role role);

    // 批量删除
    void deleteByIds(String[] ids);

    // 模糊查询
    List<SysLog> findByName(String nameStr);
    @Delete("delete from role_permission where roleId=#{roleId}")
    void deletePermission(String roleId);

    @Insert("insert into role_permission (permissionId,roleId) values (#{permissionId},#{roleId})")
    void updatePermission(@Param("roleId") String roleId,@Param("permissionId") String permissionId);

}
